package com.charm.restaurant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.charm.restaurant.common.Result;
import com.charm.restaurant.entity.Points;
import com.charm.restaurant.entity.PointsRecord;
import com.charm.restaurant.service.PointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 积分控制器
 */
@Slf4j
@RestController
@RequestMapping("/points")
public class PointsController {

    @Autowired
    private PointsService pointsService;

    /**
     * 获取用户积分信息
     */
    @GetMapping("/info")
    public Result<Points> info() {
        log.info("获取用户积分信息");
        return pointsService.getUserPoints();
    }

    /**
     * 获取用户积分记录
     */
    @GetMapping("/records")
    public Result<Page<PointsRecord>> records(int page, int pageSize) {
        log.info("获取用户积分记录，page={}, pageSize={}", page, pageSize);
        return pointsService.getPointsRecords(page, pageSize);
    }

    /**
     * 签到获取积分
     */
    @PostMapping("/signIn")
    public Result<String> signIn() {
        log.info("用户签到");
        return pointsService.signIn();
    }

    /**
     * 获取积分统计信息
     */
    @GetMapping("/statistics")
    public Result<Map<String, Object>> statistics() {
        log.info("获取积分统计信息");
        return pointsService.getPointsStatistics();
    }
}
